#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;


#define MOD 1000000007
int n, m, i;

typedef struct Point{
	int p;
	bool f;
	int id;
};
inline
bool operator<(const Point &a, const Point &b){
	return a.p < b.p ? 1 : (a.p==b.p ? (!a.f) : 0);
}

long long idSum[100000];
Point p[200000];

void read(){
	scanf("%d%d", &n, &m);
	for(i=0;i<m;++i)idSum[i]=0;
	
	m*=2;
	for(i=0;i<m;i+=2){
		scanf("%d%d", &p[i].p, &p[i+1].p);
		p[i].id=i/2;
		p[i+1].id=i/2;
		p[i+1].f=1;
	}
	
}

void process(){
	long long cur, sum;
	sort(p, p+m);
	for(i=0;i<m;++i)printf("%d| %d:%d\n", p[i].id, p[i].p, p[i].f);
	if(p[--m].p!=n){
		printf("0");
		return;
	}
	
	cur = idSum[p[m].id] = 1;
	sum=0;
	for(i=m-1;i>-1&&p[i].p;--i){
		if(p[i].f){
			if(p[i].p==p[i+1].p){
				sum=(sum+cur)%MOD;
				idSum[p[i].id]=cur;
			}
			else{
				cur=(cur+sum)%MOD;
				idSum[p[i].id]=cur;
				sum=cur;
			}
		}
		else{
			cur=(cur+sum-idSum[p[i].id])%MOD;
			sum=0;
		}
	}
	long long resp=0;
	for(;i>-1;--i)resp=(resp+idSum[p[i].id])%MOD;
	
	cout<<resp;
	//for(i=0;i<(m+1)/2;++i)printf("%d ", idSum[i]);
}

int main(){ 
	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	read();
	process();
	return 0;
}
